package com.yociyy.security.store;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 自定义Oauth2 TokenStore配置类（采用nosql存储token）
 * 
 * @author: YoCiyy
 * @date: 2020/6/30
 */
@ConditionalOnProperty(prefix = "yoci.security.oauth2.tokenStore", name = "type", havingValue = "redis")
@AllArgsConstructor
@Slf4j
public class CacheTokenStore {

	private final RedisConnectionFactory redisConnectionFactory;

	@Bean
	public TokenStore tokenStore() {
		log.info("tokenStore.type: redis");
		return new RedisTokenStore(redisConnectionFactory);
	}
}
